package com.tous.modules.handler;

import com.tous.modules.service.UdpServer;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;

/**
 * @author mengwei
 * @description UdpServerHealthIndicator
 * @createDate 2025/7/16 15:32
 */

public class UdpServerHealthIndicator implements HealthIndicator {

    private final UdpServer udpServer;

    public UdpServerHealthIndicator(UdpServer udpServer) {
        this.udpServer = udpServer;
    }

    @Override
    public Health health() {
        if (udpServer.isRunning()) {
            return Health.up()
                    .withDetail("port", udpServer.getPort())
                    .withDetail("uptime", udpServer.getUptime())
                    .build();
        }
        return Health.down().withDetail("error", "UDP服务器未运行").build();
    }
}
